<template>
    <div class="jobcommon EditResumeInfo">
        <div class="smalbox">
            <div class="backnavjob">
                <h1 @click="closejibenxinxi('close')">
                    <img
                        data-v-61dd7a3d=""
                        src="../../assets//newimg/index/icon_right_h.png"
                        alt=""
                    />
                </h1>
                <h2>
                    <span>简历-教育经历</span>
                </h2>
                <h3></h3>
            </div>

            <div class="list_height plist-txt notarrow">
                <div class="pic"></div>
                <div class="tit font14">
                    学校名称<span class="font_red_light">*</span>
                </div>
                <div class="describe font13">
                    <input
                        type="text"
                        id="school"
                        placeholder="请输入学校名称"
                        value=""
                        v-model="info.school"
                    />
                </div>
                <div class="arrow"></div>
                <div class="clear"></div>
            </div>
            <div class="list_height plist-txt notarrow">
                <div class="pic"></div>
                <div class="tit font14">
                    专业名称<span class="font_red_light">*</span>
                </div>
                <div class="describe font13">
                    <input
                        type="text"
                        id="speciality"
                        placeholder="请输入专业名称"
                        value=""
                        v-model="info.speciality"
                    />
                </div>
                <div class="arrow"></div>
                <div class="clear"></div>
            </div>
            <div class="imSelectParent" @click="xliKey = !xliKey">
                <div class="list_height plist-txt imitateSelect">
                    <div class="pic"></div>
                    <div class="tit font14">
                        学历<span class="font_red_light">*</span>
                    </div>
                    <div class="describe font13">
                        <span class="selectTxt">{{ info.education_cn }}</span>
                    </div>
                    <div class="arrow"></div>
                    <div class="clear"></div>
                </div>
            </div>
            <div
                class="list_height plist-txt qs-relative js-actionParent"
                @click="beginKey = !beginKey"
            >
                <div class="abAct js-showActionSheet"></div>
                <div class="pic"></div>
                <div class="tit font14">
                    开始时间<span class="font_red_light">*</span>
                </div>
                <div class="describe font13 qs-temp-date" data-type="start">
                    <span class="f-date-txt-start"
                        >{{ info.startyear }}年-{{ info.startmonth }}月</span
                    >
                </div>
                <div class="arrow"></div>
                <div class="clear"></div>
            </div>

            <div
                class="list_height plist-txt qs-relative js-actionParent"
                @click="endTimeKey = !endTimeKey"
            >
                <div class="abAct js-showActionSheet"></div>
                <div class="pic"></div>
                <div class="tit font14">
                    结束时间<span class="font_red_light">*</span>
                </div>
                <div class="describe font13 qs-temp-date" data-type="end">
                    <span class="f-date-txt-end"
                        >{{ info.endyear }}年-{{ info.endmonth }}月</span
                    >
                </div>
                <div class="arrow"></div>
                <div class="clear"></div>
            </div>

            <div class="j_newbutton">
                <div class="j_newbtn" @click="closejibenxinxi()">保存</div>
            </div>
            <!-- 开始时间 -->
            <component
                :is="'TimePicker'"
                v-if="beginKey"
                @changeTime="beginTimePicker"
                :year="info.startyear"
                :month="info.startmonth"
                @closeTimePciker="beginKey = false"
            ></component>
            <!-- 结束时间 -->
            <component
                :is="'TimePicker'"
                v-if="endTimeKey"
                @changeTime="endTimePicker"
                :year="info.endyear"
                :month="info.endmonth"
                @closeTimePciker="endTimeKey = false"
            ></component>
            <!-- 学历选择 -->
            <van-action-sheet
                v-model="xliKey"
                :actions="xliactions"
                @select="xliSelect"
                :duration="0.2"
            />
            <div class="zhanwei"></div>
        </div>
    </div>
</template>

<script>
import { axiosPost } from '../../axios';
import { Toast } from 'vant';
export default {
    name: '',
    props: ['education', 'dataProps'],
    data() {
        return {
            // 时间相关
            beginKey: false,
            endTimeKey: false,

            // 学历
            xliKey: false,
            xliactions: [],

            info: {
                education_cn: '',
                endmonth: '',
                endyear: '',
                id: '',
                pid: '',
                school: '',
                speciality: '',
                startmonth: '',
                startyear: '',
                todate: '',
            },
        };
    },
    computed: {},
    mounted() {
        // 设置传递过来的数据
        if (this.dataProps) {
            this.info = this.dataProps;
        }

        // 学历数据加工
        let education = [];
        for (let i in this.education) {
            education.push({
                name: this.education[i],
                id: i,
            });
        }
        this.xliactions = education;
    },
    methods: {
        closejibenxinxi(type) {
            if (type) {
                this.$emit('closeProps', { type: 3, key: false });
                return;
            }

            if (!this.info.school) {
                return Toast({
                    message: '请输入学校名称',
                    duration: 2000,
                });
            }
            if (!this.info.speciality) {
                return Toast({
                    message: '请输入专业名称',
                    duration: 2000,
                });
            }
            if (!this.info.education_cn) {
                return Toast({
                    message: '请选择学历',
                    duration: 2000,
                });
            }
            if (!this.info.startyear) {
                return Toast({
                    message: '请选择开始时间',
                    duration: 2000,
                });
            }
            if (!this.info.endyear) {
                return Toast({
                    message: '请选择结束时间',
                    duration: 2000,
                });
            }
            // console.log(JSON.parse(JSON.stringify(this.info)));
            axiosPost('/apis/resume/edit_edu', this.info, (res) => {
                Toast({
                    message: res.msg,
                    duration: 2000,
                });
                if (res.status != 1) {
                    return;
                }
                this.$emit('closeProps', { type: 3, key: true });
            });
        },
        // 学历选择
        xliSelect(item) {
            this.xliKey = false;
            this.info.education_cn = item.name;
            this.info.education = item.id;
        },
        // 开始时间
        beginTimePicker(data) {
            this.info.startyear = data.y;
            this.info.startmonth = Number(data.m);
        },
        // 结束时间
        endTimePicker(data) {
            if (!this.info.startyear) {
                return Toast({
                    message: '请先选择开始时间',
                    duration: 2000,
                });
            }
            if (data.y < this.info.startyear) {
                return Toast({
                    message: '结束时间要大于开始时间',
                    duration: 2000,
                });
            }
            if (data.y == this.info.startyear) {
                if (Number(data.m) <= this.info.startmonth) {
                    return Toast({
                        message: '结束时间要大于开始时间',
                        duration: 2000,
                    });
                }
            }
            this.info.endyear = data.y;
            this.info.endmonth = Number(data.m);
        },
    },
};
</script>
<style lang="css" src="../../assets/css/jobperson.css"></style>
<style lang="less" scope></style>
